package com.app.service.impl;

import com.app.model.KeyWorkModel;
import com.app.model.ProjectModel;
import com.app.model.SystemModel;
import com.app.service.*;
import com.app.vo.MapVo;
import com.app.vo.UserLoginVo;
import com.app.vo.ValueAndNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class HomePageServiceImpl implements HomePageService {
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ProjectProgressService projectProgressService;

    @Autowired
    private UserService userService;
    @Autowired
    private IdeaService ideaService;
    @Autowired
    private QuestionnaireService questionnaireService;
    @Autowired
    private KeyWorkService keyWorkService;
    @Override
    public Object getTypeCountStatistics() {
        Map<String, int[]> map = new HashMap<>();
        Map<String, Integer> map1 = new HashMap<>();
        Map<String, String[]> map2 = new HashMap<>();

        Calendar calendar1 = Calendar.getInstance();
        String year1 = String.valueOf(calendar1.get(Calendar.YEAR));
        ProjectModel projectModels = projectProgressService.selectCountByYear(year1);
        int redCount = projectModels.getRedCount();
        int blueCount = projectModels.getBlueCount();
        int yellowCount = projectModels.getYellowCount();
        int[] arr1 = {0, 0, 0};
        arr1[0] = blueCount;
        arr1[1] = yellowCount;
        arr1[2] = redCount;
        map.put(year1, arr1);
        int sum1 = redCount + blueCount + yellowCount;
        map1.put(year1, sum1);

        Calendar calendar2 = Calendar.getInstance();
        calendar2.add(Calendar.YEAR, -1);
        String year2 = String.valueOf(calendar2.get(Calendar.YEAR));
        ProjectModel projectModels1 = projectProgressService.selectCountByYear(year2);
        int redCount1 = projectModels1.getRedCount();
        int blueCount1 = projectModels1.getBlueCount();
        int yellowCount1 = projectModels1.getYellowCount();
        int[] arr2 = {0, 0, 0};
        arr2[0] = blueCount1;
        arr2[1] = yellowCount1;
        arr2[2] = redCount1;
        map.put(year2, arr2);
        int sum2 = redCount1 + blueCount1 + yellowCount1;
        map1.put(year2, sum2);

        Calendar calendar3 = Calendar.getInstance();
        calendar3.add(Calendar.YEAR, -2);
        String year3 = String.valueOf(calendar3.get(Calendar.YEAR));
        ProjectModel projectModels2 = projectProgressService.selectCountByYear(year3);
        int redCount2 = projectModels2.getRedCount();
        int blueCount2 = projectModels2.getBlueCount();
        int yellowCount2 = projectModels2.getYellowCount();
        int[] arr3 = {0, 0, 0};
        arr3[0] = blueCount2;
        arr3[1] = yellowCount2;
        arr3[2] = redCount2;
        map.put(year3, arr3);
        int sum3 = redCount2 + blueCount2 + yellowCount2;
        map1.put(year3, sum3);

        Calendar calendar4 = Calendar.getInstance();
        calendar4.add(Calendar.YEAR, -3);
        String year4 = String.valueOf(calendar4.get(Calendar.YEAR));
        ProjectModel projectModels3 = projectProgressService.selectCountByYear(year4);
        int redCount3 = projectModels3.getRedCount();
        int blueCount3 = projectModels3.getBlueCount();
        int yellowCount3 = projectModels3.getYellowCount();
        int[] arr4 = {0, 0, 0};
        arr4[0] = blueCount3;
        arr4[1] = yellowCount3;
        arr4[2] = redCount3;
        map.put(year4, arr4);
        int sum4 = redCount3 + blueCount3 + yellowCount3;
        map1.put(year4, sum4);

        Calendar calendar5 = Calendar.getInstance();
        calendar5.add(Calendar.YEAR, -4);
        String year5 = String.valueOf(calendar2.get(Calendar.YEAR));
        ProjectModel projectModels4 = projectProgressService.selectCountByYear(year5);
        int redCount4 = projectModels4.getRedCount();
        int blueCount4 = projectModels4.getBlueCount();
        int yellowCount4 = projectModels4.getYellowCount();
        int[] arr5 = {0, 0, 0};
        arr5[0] = blueCount4;
        arr5[1] = yellowCount4;
        arr5[2] = redCount4;
        map.put(year5, arr5);
        int sum5 = redCount4 + blueCount4 + yellowCount4;
        map1.put(year5, sum5);

        MapVo vo = new MapVo();
        vo.setTypeData(map);
        vo.setNumData(map1);
        return vo;
    }

    @Override
    public Object getUserOverview() {
        //注册用户数量
        int userCount = userService.getCount();
        //调查问卷回收
        int questionCount = questionnaireService.getCount();
        //意见建议数量
        int ideaCount = ideaService.getCount();
        //营商环境单位数量
        int departmentCount = departmentService.getDepartmentCount();
        //重点投资项目
        ProjectModel projectCount = projectProgressService.getProjectCount();
        int thisYearCount = projectCount.getThisYearCount();
        //重点工作任务
        KeyWorkModel keyWorkCount = keyWorkService.getKeyWorkCount();
        int thisYearCount1 = keyWorkCount.getThisYearCount();
        UserLoginVo vo = UserLoginVo.builder()
                .userCount(userCount)
                .questionCount(questionCount)
                .ideaCount(ideaCount)
                .departmentCount(departmentCount)
                .keyWorkCount(thisYearCount1)
                .projectCount(thisYearCount)
                .build();
        return vo;
    }
}
